//
//  RecommendViewController.m
//  JZMCFM
//
//  Created by Mc on 15/10/30.
//  Copyright (c) 2015年 陈卓. All rights reserved.
//

#import "RecommendViewController.h"
#import "RecommendView.h"
#define  kscreenwidth [UIScreen mainScreen].bounds.size.width
#define  kscreenHeight [UIScreen mainScreen].bounds.size.height
@interface RecommendViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong)RecommendView *recommendView;
@property (nonatomic, strong)NSMutableArray *RecommenddataArray;

@end

@implementation RecommendViewController

-(void)loadView
{
    self.recommendView = [[RecommendView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.view = self.recommendView;
    self.recommendView.RecommendTableView.contentInset = UIEdgeInsetsMake(0, 0, 101, 0);
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //self.navigationController.navigationBar.translucent = NO;
    
    self.recommendView.RecommendTableView.delegate = self;
    self.recommendView.RecommendTableView.dataSource = self;
 
    
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"%@00000000",[RecommedHelper shareInstance].titleArray);
    return  [RecommedHelper shareInstance].titleArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (0 == section) {
        return 1;
    }else if (1 == section){
        return 2;
        
    }
//        else if (2 == section){
//        return 4;
//    }
        else{
        return 1;
    }

    
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (0 == indexPath.section ) {
        

      static NSString *cell_id = @"cell1";
        RecommedTableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:cell_id];
        if (cell1 == nil) {
            cell1 = [[RecommedTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
        }
        
        RecommedModel *model = [RecommedHelper shareInstance].editorRecommendAlbumsArray[indexPath.row];
        [cell1 setdataCellWithModel:model];
        
      
        
        return cell1;
        
        
        
    }else if (1 == indexPath.section){
        static NSString *cell_idd = @"cell2";
        RecommendCollectionViewCelltwo *cell2 = [tableView dequeueReusableCellWithIdentifier:cell_idd];
        if (cell2 == nil) {
            cell2 = [[RecommendCollectionViewCelltwo alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_idd];
        }
        RecommedModel *model = [RecommedHelper shareInstance].specialColumnArray[indexPath.row];
        [cell2 setCellModelData:model];
      
        return cell2;
        
        
//    }else if(2== indexPath.section){
//        static NSString *cell_iddd = @"cell3";
//        RecomendCollectionViewCellThree *cell3 = [tableView dequeueReusableCellWithIdentifier:cell_iddd];
//        if (cell3 == nil) {
//            cell3 = [[RecomendCollectionViewCellThree alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_iddd];
//        }
//        RecommedModel *model = [RecommedHelper shareInstance].discoveryColumnsArray[indexPath.row];
//        [cell3 setcellDataModel:model];
//        
//        return cell3;
    }
    else{
        
        static NSString *cell_idddd = @"cell9";
        RecommedTableViewCell *cell1111 = [tableView dequeueReusableCellWithIdentifier:cell_idddd];
        if (cell1111 == nil) {
            cell1111 = [[RecommedTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_idddd];
        }
        NSLog(@"%ld-----",[RecommedHelper shareInstance].aaaa.count);
        NSArray *arr = [RecommedHelper shareInstance].aaaa[indexPath.section-2];
        [cell1111 setdataCellWithModel11:arr];
       
        return cell1111;
        
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 150;
    }else if (indexPath.section == 1)
    {
        return 95;
        
//    }else if (indexPath.section == 2){
//        return 95;
    }else{
        return 150;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 180;
    }else{
        return 20;
    }
}





- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kscreenwidth, 150)];
        NSMutableArray *imageArray = [NSMutableArray array];
        for (int i = 0; i < [RecommedHelper shareInstance].RecommedDataArray.count; i++) {
            NSLog(@"%ld",[RecommedHelper shareInstance].RecommedDataArray.count);
            RecommedModel *model = [RecommedHelper shareInstance].RecommedDataArray[i];
            [imageArray addObject:model.pic];
        }
        SDCycleScrollView * cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kscreenwidth, 180) imageURLStringsGroup:imageArray];
        cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolAlimentRight;
        cycleScrollView.autoScrollTimeInterval =3;
        cycleScrollView.dotColor = [UIColor grayColor];
        [view addSubview:cycleScrollView];
        return view;
    }else if(section == 1){
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, kscreenwidth, 10)];
        label.text = [RecommedHelper shareInstance].titleArray[section];
        label.font = [UIFont systemFontOfSize:14];
        
        return label;
    }
//        else if (section == 2){
//        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, kscreenwidth, 20)];
//        label.text = [RecommedHelper shareInstance].titleArray[section];
//        label.font = [UIFont systemFontOfSize:14];
//        label.tintColor = [UIColor redColor];
//        return label;
//    }
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5,0, kscreenwidth, 10)];
    label.text = [RecommedHelper shareInstance].titleArray[section];
    label.font = [UIFont systemFontOfSize:15];
    label.tintColor = [UIColor redColor];
    return label;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
 
    RecommendDetailController *vc = [[RecommendDetailController alloc]init];
    vc.title11 = [RecommedHelper shareInstance].titleArray[indexPath.section];
    
    
    [self.navigationController pushViewController:vc animated:YES];
    

    
}


@end
